package cn.dengta.webapp.im.entity;

import cn.dengta.common.model.BizFlag;
import cn.dengta.common.model.Status;
import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;

/**
 * 渠道推荐配置
 *
 * @author hsj
 * @since 2024-01-18
 */
@Setter
@Getter
@TableName("dt_channel_rec_config")
public class ChannelRecConfig extends TimeBasedEntity implements BizFlag.WritableBizFlag {

	/** 标识：是否勾选聊天列表 */
	public static final long BIZ_FLAG_ANCHOR_LIST = 1L;

	/** 标识：是否勾选在线列表 */
	public static final long BIZ_FLAG_ONLINE_LIST = 1L << 1;

	/** 开关（0=未开启；1=开启） */
	Integer status;
	/** （条件）多少分钟内 */
	Integer conditionBetweenMinutes;
	/** （条件）超过搭讪数 */
	Integer conditionGreetNum;
	/** 多少分钟（分钟）后重新进入 */
	Integer inMinutes;
	/** 指定渠道 */
	String channel;
	/** 分包 */
	Integer wesKit;
	/** 版本号 */
	String version;
	/** 退出的业务标识（按位存储）第一位：聊天列表，第二位：在线列表 */
	Long outFlag;
	/** 限制省，逗号分割 */
	String provinces;
	/** 限制市，逗号分割 */
	String cities;

	public static final String STATUS = "status";
	public static final String CONDITION_BETWEEN_MINUTES = "condition_between_minutes";
	public static final String CONDITION_GREET_NUM = "condition_greet_num";
	public static final String IN_MINUTES = "in_minutes";
	public static final String CHANNEL = "channel";
	public static final String WES_KIT = "wes_kit";
	public static final String VERSION = "version";
	public static final String OUT_FLAG = "out_flag";
	public static final String PROVINCES = "provinces";
	public static final String CITIES = "cities";

	public boolean selectAnchorList() {
		return hasFlag(BIZ_FLAG_ANCHOR_LIST);
	}

	public boolean selectOnlineList() {
		return hasFlag(BIZ_FLAG_ONLINE_LIST);
	}

	@Override
	public void setBizFlag(long l) {
		this.outFlag = l;
	}

	@Override
	public long getBizFlag() {
		return outFlag;
	}

	public boolean isOpen() {
		return Status.YES.eq(status);
	}

	public String getCacheKey() {
		return getCacheKey(channel, WesKit.of(wesKit));
	}

	public static String getCacheKey(String channel, WesKit wesKit) {
		return channel + (wesKit == null ? "" : "_" + wesKit.name());
	}


}
